package models

import (
	"192.168.1.75/go-pkg/helper"
	"gorm.io/gorm"
)

// Floor 楼层
type Floor struct {
	ID         string `json:"id" gorm:"column:id;primaryKey;type:int;size:64;comment:主键id"`
	Name       string `json:"name" gorm:"column:name;index:name_location,unique;type:string;size:40;comment:楼层名称"`
	Sort       int    `json:"sort" gorm:"column:sort;type:int;size:8;comment:排序"`
	NavName    string `json:"nav_name" gorm:"column:nav_name;type:string;size:40;default:null;comment:导航名称"`
	Map        string `json:"map" gorm:"column:map;type:string;size:200;default:null;comment:导航地图"`
	LocationID string `json:"location_id" gorm:"column:location_id;index:name_location,unique;type:int;size:64;comment:位置"`
	CreatedAt  int64  `json:"-" gorm:"column:created_at;autoCreateTime;type:int;size:64;comment:创建时间"`
	UpdatedAt  int64  `json:"-" gorm:"column:updated_at;autoUpdateTime;type:int;size:64;comment:更新时间"`
}

// TableName 表名
func (Floor) TableName() string {
	return "floor"
}

// BeforeCreate 自增id
func (l *Floor) BeforeCreate(tx *gorm.DB) (err error) {
	if l.ID != "" {
		return nil
	}
	// 用户id为空时，自动添加用户id
	uuid, err := helper.UUID{}.String()
	if err != nil {
		return err
	}
	l.ID = uuid
	return nil
}

// 模式自动注册
func init() {
	Models = append(Models, &Floor{})
}
